<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改合同产品表')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-contractProduct-edit" th:object="${contractProduct}">
            <input name="contractProductId" th:field="*{contractProductId}" type="hidden">
            <input name="contractType" th:field="*{contractType}" type="hidden">
            <input name="productId" th:field="*{productId}" type="hidden">
            <input name="contractId" th:field="*{contractId}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">合同编码：</label>
                <div class="col-sm-8">
                    <input name="contractCode" th:field="*{contractCode}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">产品名称：</label>
                <div class="col-sm-8">
                    <input name="name" th:field="*{name}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">产品名称：</label>
                <div class="col-sm-8">
                    <input name="code" th:field="*{code}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">产品价格：</label>
                <div class="col-sm-8">
                    <input name="price" th:field="*{price}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">合同数量：</label>
                <div class="col-sm-8">
                    <input name="num" th:field="*{num}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label useNum">使用数量：</label>
                <div class="col-sm-8">
                    <input name="useNum" th:field="*{useNum}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label remainNum">剩余数量：</label>
                <div class="col-sm-8">
                    <input name="remainNum" th:field="*{remainNum}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label operationNum">操作数量：</label>
                <div class="col-sm-8">
                    <input name="operationNum"  class="form-control" type="number" th:value="*{remainNum}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input name="remark"  class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "contract/contractProduct";

        let contractProduct=[[${contractProduct}]]
        if(contractProduct.contractType==contractTypeObj.buy){
            $(".useNum").text("已入库数量");
            $(".remainNum").text("待入库数量");
            $(".operationNum").text("本次入库数量");
        }else if(contractProduct.contractType==contractTypeObj.sell){
            $(".useNum").text("已出库数量");
            $(".remainNum").text("待出库数量");
            $(".operationNum").text("本次出库数量");
        }

        $("#form-contractProduct-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            let remainNum=Number($("input[name='remainNum']").val())||0;
            let operationNum=Number($("input[name='operationNum']").val())||0;
            if(remainNum==0){
                let title=contractProduct.contractType==contractTypeObj.buy?"已经完成入库":"已经完成出库";
                $.modal.alertWarning(title);
                return;
            }
            if(operationNum>remainNum){
                let title=contractProduct.contractType==contractTypeObj.buy?"本次入库":"本次出库";
                let title1=contractProduct.contractType==contractTypeObj.buy?"待入库数量":"待出库数量";
                $.modal.alertWarning("【"+title+"："+operationNum+" 】 > 【"+title1+"："+remainNum+"】");
                return;
            }
            if ($.validate.form()) {
                var data= $('#form-contractProduct-edit').serialize();
                $.operate.save(prefix + "/edit", $('#form-contractProduct-edit').serialize());
            }
        }
    </script>
</body>
</html>
